<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<title>在线答题</title>
<link rel="stylesheet" type="text/css"
	href="<%=basePath%>css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/paper.css">
<script src="<%=basePath%>js/jquery.js" type="text/javascript"></script>
<script src="<%=basePath%>js/bootstrap.js"></script>
   <style type="text/css">
     .center{
        text-align: center;
        margin-top: 50pt;
        }
        </style>
<script type="text/javascript">
  var count = 3;
  function countdown() {
    if (count == 0) {
      window.location.href = "login.jsp";
    } else {
      document.getElementById("countdown").innerHTML = count;
      count--;
      setTimeout(countdown, 1000);
    }
  }
</script>
</head>

<body>
	<%
  // 获取 Session 对象
  	HttpServletRequest req = (HttpServletRequest)request;
		HttpServletResponse rsp = (HttpServletResponse)response;
		HttpSession session1 = req.getSession();
		if(session1==null || session1.getAttribute("user")==null){%>
			<!-- //处理未登陆问题。重定向到登陆页面
			String path = req.getContextPath();
			String basePath = req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+path+"/"; -->
			<div class="center">
			<p>你还未登录！</p>
			<p>
				<span id="countdown">3</span> 秒后跳转到登录页面。
			</p>
			<script type="text/javascript">
				countdown();
			</script>
	</div>
			
 <%  } else {
%>
   <nav class="navbar navbar-default" role="navigation">
		<!-- Brand and toggle get grouped for better mobile display -->
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-ex1-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="#">在线考试系统</a>
		</div>

		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse navbar-ex1-collapse">
			<ul class="nav navbar-nav">
				<li class="active"><a href="<%=basePath%>user?cmd=paperlist">试题列表</a></li>
				<li><a href="<%=basePath%>user/studentPaper?cmd=stupaper">查看错题</a></li>
			</ul>
			<ul class="nav navbar-nav navbar-right">
				<c:choose>
					<c:when test="${userid!=null}">
						<li><a> <c:out value="${sessionScope.user.usertruename}" />
						</a></li>
						<li><a href="<%=basePath%>sys/user?cmd=logout">注销</a></li>
					</c:when>
					<c:otherwise>
						<li><a href="login.jsp">登录</a></li>
					</c:otherwise>
				</c:choose>

			</ul>
		</div>
		<!-- /.navbar-collapse -->
	</nav>

	<main class="container">
		<div class="panel panel-default">
			<div class="panel-heading text-center">
				<h3 class="panel-title">查看试题</h3>
			</div>
			<div class="panel-body">
				<div class="well">
					<table class="table">
						<thead>
							<tr>
								<th>试题名称</th>
								<th>题目数量</th>

								<th style="width: 90px;">操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${papers}" var="item">
								<tr>
									<td>${item.pname}</td>
									<td>${item.scount}</td>

									<td><a
										href="<%=basePath%>user?cmd=paper&pname=${item.pname}">开始答题</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</main>
<%
  }
%>
</body>

</html>